<!DOCTYPE html>
<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<html>
<head>
<title>${name_china}管理列表</title>
<%@include file="/common/head.jsp" %>

<!-- 时间日期插件 -->
<link href="<%=request.getContextPath()%>/static/plugin/My97DatePicker/skin/default/datepicker.css" rel="stylesheet" >
<script src="<%=request.getContextPath()%>/static/plugin/My97DatePicker/WdatePicker.js"></script>

</head>
<body class="iframe-page">
<div class="page-title-wrapper">
    <div class="page-title">
        <div class="page-title-text">
            <span>${name_china}管理</span>
        </div>
        <div id="toolbar" style="float: right"></div>
    </div>
    <div class="page-title-border"></div>
</div>

<div class="search-field">
    <span class="field-cont">
        <span class="field-cont-title">备注</span>
        <input type="text" class="summer-input" id="note" name="note"/>
    </span>
    
     <span class="field-cont">
        <span class="field-cont-title">日期</span>
        <input type="text" class="summer-input" onFocus="WdatePicker({dateFmt:'yyyy-MM-dd'})" id="createTime" name="createTime"/>
    </span>
    
    
    <span class="field-btn-wrapper">
        <a id="search" class="btn btn-primary btn-icon wave distance-right"><i class="icon icon-search"></i></a>
        <a id="reset" class="btn btn-icon wave wave-dark"><i class="icon icon-refresh"></i></a>
    </span>
</div>

<div id="t-wrap">
    <table class="summer-datagrid" id="dataList">
	    <thead>
		    <tr>
		        <th>当前请求次数</th>
		        <th>请求参数</th>
		        <th>请求商品sku</th>
		        <th>返回二合一链接</th>
		        <th>请求时间</th>
		        <th>备注</th>
		    </tr>
	    </thead>
    </table>
</div>

<script>
	//请求url
	var CONST_URL = {
		LIST: basePath + '${common_url}list?categoryId=${categoryId}',
	   	INIT_ADD: basePath + "${common_url}initAdd?categoryId=${categoryId}",
	   	INIT_EDIT: basePath + "${common_url}initEdit?categoryId=${categoryId}",
	   	INIT_HONGBAO: basePath + "${common_url}initHongbao?categoryId=${categoryId}",
	   	INIT_ORDER: basePath + "${common_url}initOrder?categoryId=${categoryId}",
	   	INIT_BAOKUAN: basePath + "${common_url}initBaokuan?categoryId=${categoryId}",
		INIT_JINGXUAN: basePath + "${common_url}initJingxuan?categoryId=${categoryId}",
		DEL_BAOKUAN: basePath + "${common_url}delBaokuan",
		DEL_JINGXUAN: basePath + "${common_url}delJingxuan",
		SYNCPRODUCT: basePath + "${common_url}syncproduct",
		FILTERPRODUCT: basePath + "${common_url}filterproduct",
	   	DEL: basePath + "${common_url}del"
	};
	
    var  permission = CommonUtil.getPermission('${name_english}');
    
    $(function () {
    	
        // 新建toobar
		$.funcbar({
			id: 'toolbar',
			type: 'toolbar',
			data: permission,
			permit: ['${name_english}:filterproduct','${name_english}:syncproduct'],
		});
        
        // 查询按钮
        $('#search').on('click', reloadTable);
        
        //重置按钮
        $('#reset').on('click', function () {
        	//重置文本框的值
        	$('#goodsName').val('');
        	reloadTable();
        });
        
        
        //新建
        $('#toolbar').on('click', 'a[data-permit="${name_english}:initAdd"]', function() {
        	window.location.href = CONST_URL.INIT_ADD;
		});
        
        
       createTable();
        
        
        //
        $('#t-wrap').on('click', 'a[data-permit="${name_english}:initOrder"]', function() {
        	var $this = $(this),
        	    id = $this.closest('tr').find('td[data-field="id"]').attr('data-value');
        	window.location.href = CONST_URL.INIT_ORDER +"&id=" + id;
        });
       
        
        //编辑
        $('#t-wrap').on('click', 'a[data-permit="${name_english}:initEdit"]', function() {
            var $this = $(this),
                id = $this.closest('tr').find('td[data-field="id"]').attr('data-value');
            window.location.href = CONST_URL.INIT_EDIT + '&id=' + id;
        });	
        
        
        //编辑
        $('#t-wrap').on('click', 'a[data-permit="${name_english}:initBaokuan"]', function() {
            var $this = $(this),
                id = $this.closest('tr').find('td[data-field="id"]').attr('data-value');
            window.location.href = CONST_URL.INIT_BAOKUAN + '&id=' + id;
        });	
        
        //编辑
        $('#t-wrap').on('click', 'a[data-permit="${name_english}:initJingxuan"]', function() {
            var $this = $(this),
                id = $this.closest('tr').find('td[data-field="id"]').attr('data-value');
            window.location.href = CONST_URL.INIT_JINGXUAN + '&id=' + id;
        });	
        
        //删除
		$('#t-wrap').on('click', 'a[data-permit="${name_english}:del"]', function() {
			var $this = $(this),
			    id = $this.closest('tr').find('td[data-field="id"]').attr('data-value');
			$.sdialog({
				type: 'confirm',
				msg: '您确定要删除选中的记录吗?',
				onConfirm: function(result) {
				    if (result) {
				    	$.sajax({
			                url : CONST_URL.DEL + "?id=" + id,
			                onLoadSuccess : function() {
			                	 $.stip({
                	                type:'ok',//显示类型 有info、 ok、 danger
                	                text: '删除成功！'    
			                	});
			                	reloadTable();  
			                }
			            });
				    		
				    }	
				}
			});
		});
        
        
        
    });
    
    // 重新加载表格
	function reloadTable() {
		$('#dataList').datagrid('reload',{
            ajax: {
            	param: {
            		"note": trimSpace($('#note').val()),
            		"createTime": $("#createTime").val()
            	}
            }
        });
	}
    
    //创建表格
    function createTable() {
    	$('#dataList').datagrid({
    		ajax: {
    			url: CONST_URL.LIST,
    			param: {
    				"note": trimSpace($('#note').val()),
            		"createTime": $("#createTime").val()
            	}
    		},
    		columns: [
    		     {
    		    	 field: 'id',
    		    	 hidden: true
    		     },
    		     {
    		    	 field: 'reorder',
    		    	 render: function (rowData) {
    		    		 if(rowData.reorder){
    		    			 return rowData.reorder;
    		    		 }else{
    		    			 return "无排序号";
    		    		 }
    		    	 }
    		     },
    		     {
    		    	 field: 'userName'
    		     },
    		     {
    		    	 field: 'productSku'
    		     },
    		     {
    		    	 field: 'returnStatus'
    		     },
    		     {
    		    	 field: 'createTime'
    		     },
    		     {
    		    	 field: 'note'
    		     }
    		          
    	    ]
    	});
    }
    
    
   
</script>
</body>
</html>